package com.chis.jxc;

import com.chis.jmdatatimer.comm.TxMgmtModule;
import com.chis.jxc.bean.OrderNum;
import com.chis.jxc.bean.PurInfobean;
import com.chis.jxc.bean.Purbean;
import com.chis.util.RandomGUID;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.LinkedList;
import java.util.List;

/**
 * 
 * @Description 1、生成入库交易记录；2、处理订单流程节点表
 * @Company zwx
 * @author wlj
 * @version 2019年12月04日
 */
public class StoreData {
    public static void main(String[] args) throws Exception {
        String opt = args[0];
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"spring.xml"});
        context.start();
        TxMgmtModule txMgmtModule = (TxMgmtModule) context.getBean("TxMgmtModule");
        if(opt.equals("1")){
            System.out.println("==============================处理入库交易数据");
            String[] zone = new String[]{"3200","3201","3202","3203","3204","3205","3206","3207","3208","3209","3210","3211","3212","3213"};
            for(String z : zone){
                List<Purbean> cntStmCodes = txMgmtModule.findPurinfo(z);
                List<PurInfobean> tmp = new LinkedList<>();
                int i = 0;
                for(Purbean t : cntStmCodes){
                    if(i > 500){
                        txMgmtModule.savePurinfo(tmp);
                        i = 0;
                        tmp = new LinkedList<>();
                    }
                    PurInfobean bean = new PurInfobean();
                    bean.setGuid(new RandomGUID().toString());
                    bean.setUnitCode(t.getUnitCode());
                    bean.setConUnitCode(t.getConUnitCode());
                    bean.setBatnmb(t.getBatnmb());
                    bean.setBcatCode(t.getBcatCode());
                    tmp.add(bean);
                    i++;
                }
                if(tmp.size() > 0){
                    txMgmtModule.savePurinfo(tmp);
                }
                System.out.println("=====入库交易执行结束："+z);
            }
        }
        if(opt.equals("2")){
            System.out.println("==============================处理订单数据");
            List<OrderNum> list = txMgmtModule.findOldOrder();
            for(OrderNum t : list){
                txMgmtModule.updateOrderFlow(t);
            }
        }

        System.out.println("==============================处理结束");
    }
}
